package com.lansetech.framework.redis.peak.shaving;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.lang.management.ManagementFactory;
import java.util.Locale;

/**
 * Hello world!
 */
public class Main {
    public static void main(String[] args) {

        JedisPoolConfig config = new JedisPoolConfig();
        JedisConnectionFactory connectionFactory = new JedisConnectionFactory(config);
        connectionFactory.afterPropertiesSet();

        Locale.setDefault(Locale.PRC);


        MessageConsumer consumer = new MessageConsumer() {
            @Override
            public void consume(String type, String value) {
                System.out.println(value);
            }

            @Override
            public void handleFailure(String type, String value, Exception e) {
                e.printStackTrace();
            }
        };
        PeakShavingListener listener = new PeakShavingListener(connectionFactory, consumer, 30);
        listener.init();
        listener.start();
    }
}
